<div class="content-wrapper">
    <section class="content-header">
        <h1>文档列表</h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">系统配置</li>
            <li class="active">文档列表</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
                <form class="form-inline" action="/admin/document/docList" method="get">
                    <div class="form-group">
                        <label for="name">名称 </label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="文件名称" value="{$name}">
                    </div>
                    <button type="submit" class="btn btn-info" id="save-btn">查询</button>
                    <button type="button" class="btn btn-success" id="makeDir">创建目录</button>
                    <button type="button" class="btn btn-danger" id="uploadFile">上传文件</button>
                </form>
            </div>
            <div class="box-body table-responsive no-padding">
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                        <th colspan="3">
                            当前路径：{$currentData.file_path}
                        </th>
                        <th colspan="2" class="text-right">
                            <a href="/admin/document/docList?pid={$currentData.pid}">返回上一级</a>
                        </th>
                    </thead>
                    <tbody>
                    <tr>
                        <th style="width: 80px">ID</th>
                        <th>名称</th>
                        <th>类型</th>
                        <th>状态</th>
                        <th style="width: 200px">操作</th>
                    </tr>
                    <if condition="count($docList) eq 0"><tr><td class="text-center" colspan="5">暂无数据...</td></tr></if>
                    <foreach name="docList" item="item">
                        <tr>
                            <td>{$item.id}</td>
                            <td><a href="javascript:void(0)" title="{$item.file_path}">{$item.name}</a></td>
                            <td><label class="label {$type[$item['type']]['class']}">{$type[$item['type']]['name']}</label></td>
                            <td>
                                <if condition="$item.status eq 1 ">
                                    <span class="label label-success">已开启</span>
                                    <else />
                                    <span class="label label-warning">已关闭</span>
                                </if>
                            </td>
                            <td>
                                <if condition="$item.type eq 0 ">
                                    <a href="javascript:void(0)" class="btn btn-info btn-xs" onclick="entryDir('{$item.id}')">进入</a>
                                    <else />
                                    <a href="/admin/index/downloadFile?file={$item.file_path|urlencode}" class="btn btn-primary btn-xs">下载</a>
                                </if>
                                <button class="btn btn-danger btn-xs btn-delete" type="button" data-id="{$item.id}">删除</button>&nbsp;
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>
            <div class="box-footer clearfix">{$page_html}</div>
        </div>
    </section>
</div>
<script src="__PUBLIC__/global/AjaxUpload.js"></script>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script>
    $(".btn-delete").click(function () {
        var id = $(this).attr('data-id');
        layer.confirm('确定删除吗？', {
            icon: 3,
            title:'警告'
        }, function(){
            $.post('/admin/document/ajaxDeleteDoc',{
                id: id
            },function (_data ) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:1000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
            },"JSON");
        }, function(){
            //layer.msg('取消了', {icon: 2});
        });

        /*var id = $(this).attr('data-id');
        ArtDialogHlp.showConfirm("提示","确认删除该文档吗？",function () {
            $.post('/admin/document/ajaxDeleteDoc',{
                id: id
            },function (_data) {
                if(_data.Code==999){
                    layer.msg("操作成功",{time:1000});
                    window.location.reload(true);
                }else{
                    layer.msg(_data.Msg,{time:1000});
                    return false;
                }
            },"JSON");
        });*/
    });
    function entryDir(pid, name) {
        window.location.href='/admin/document/docList?pid='+pid;
    }
    $(function(){
        $('#makeDir').on('click', function (e) {
            layer.prompt({
                title: '创建目录',
                formType: 0,
                value: '', //初始时的值，默认空字符
                maxlength: 50 //可输入文本的最大长度
            }, function(value, index, elem){
                console.log(value);
                console.log(elem);
                $.post('/admin/document/docMakeDir',{
                    name : value,
                    pid : '{$pid}'
                },function (_data) {
                    if(_data.Code==999){
                        layer.msg('创建成功',{time:1000});
                        layer.close(index);
                        window.location.reload(true);
                    }else{
                        layer.msg(_data.Msg,{time:1000});
                        return false;
                    }
                },"JSON");
            });
        });

        new AjaxUpload("#uploadFile", {
            action: '/admin/document/ajaxUploadFile',
            type:"POST",
            name:'import',
            data:{pid: '{$pid}'},
            responseType: 'json',
            onSubmit: function(file, ext) {
                var allowExt = "'xls','xlsx','doc','pdf','docx','png','jpeg','jpg'";
                if(allowExt.indexOf(ext)<0){
                    layer.msg("请上传"+allowExt+"格式的文件");
                    return false;
                }
                layer.load(1, {
                    shade: [0.48,'#999'] //0.1透明度的白色背景
                });
            },
            onComplete: function(file, response) {
                layer.closeAll('loading');
                if(response.Code ==999) {
                    layer.msg('上传成功');
                    window.location.reload(true);
                }else{
                    layer.msg(response.Msg);
                    return false;
                }
            }
        });
    });
</script>